package com.smart.util;

import com.smart.common.util.IErrorCode;
import com.smart.common.util.ResultCode;

public class Messages<T> {

    private long code;
    private String message;
    private T data;

    public Messages(long code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功返回结果
     * @param data 获取的数据
     **/
    public static <T> Messages<T> success(T data) {
        return new Messages<>(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),data);
    }

    /** 未授权返回结果 */
    public static <T> Messages<T> forbidden(T data) {
        return new Messages<>(ResultCode.FORBIDDEN.getCode(),ResultCode.FORBIDDEN.getMessage(),data);
    }
    /** 未登录返回结果 */
    public static <T> Messages<T> unauthorized(T data) {
        return new Messages<>(ResultCode.UNAUTHORIZED.getCode(),ResultCode.UNAUTHORIZED.getMessage(),data);
    }
    
    /** 参数验证失败返回结果 */
    public static <T> Messages<T> validateFailed() {
        return failed(ResultCode.VALIDATE_FAILED);
    }
    /**
     * 参数验证失败返回结果
     * @param message 提示信息
     **/
    public static <T> Messages<T> validateFailed(String message) {
        return new Messages<>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
    }
    /**
     * 失败返回结果
     * @param message 提示信息
     **/
    public static <T> Messages<T> failed(String message) {
        return new Messages<>(ResultCode.FAILED.getCode(), message, null);
    }
    /**
     * 失败返回结果
     * @param errorCode 错误码
     **/
    public static <T> Messages<T> failed(IErrorCode errorCode) {
        return new Messages<>(errorCode.getCode(), errorCode.getMessage(), null);
    }
    public long getCode() {
        return code;
    }
    public void setCode(long code) {
        this.code = code;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public T getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }
}